import test from 'ava';
import {parseInfo} from 'd-fi-core';
import {saveLayout, getFileSize, progressBar} from '../../src/lib/util';

test('SAVE LAYOUT', async (t) => {
  const {tracks, linkinfo} = await parseInfo('https://www.deezer.com/track/3135556');
  const layout = saveLayout({
    track: tracks[0],
    album: linkinfo,
    path: 'Music/{ALB_NAME}/{ART_NAME}/{SNG_TITLE}',
    minimumIntegerDigits: 2,
    trackNumber: true,
  });
  t.is(layout, 'Music/Daft Punk/04 - Harder, Better, Faster, Stronger');
});

test('FILE SIZE', async (t) => {
  const size = await getFileSize('https://file-examples-com.github.io/uploads/2017/11/file_example_MP3_2MG.mp3', 0);
  t.is(size, 2113939);
});

test('PROGRESS BAR', (t) => {
  const bar = progressBar(1000, 40);
  t.is(typeof bar, 'function');

  const len = bar(500);
  t.is(len.length, 40);
});
